<?php
/**
 +------------------------------------------------------------------------------
 * 常量节点模型
 +------------------------------------------------------------------------------
 */
class ConstantNodeModel extends CommonModel
{
	protected $_validate = array(
		array('constant_id','require','{%CONSTANT_ID}'),
                array('constant_id','number','{%CONSTANT_UNIQUE}'),
                array('status','number','{%STATUS_UNIQUE}'),
                array('name','require','{%NAME_REQUIRE}'),
                array('constant_title','require','{%TITLE_REQUIRE}'),
                array('sort','number','{%SORT_REQUIRE}'),
	);
        protected $_auto=array(
            array('operatetime','time',3,'function'),
            array('constant_name','get_constant_name',3,'callback'),
        );
        
        /**
     * 根据提交的$_POST constant_id获取常量的名称
     * @return String 常量名称 
     */
    public function get_constant_name() {
        $id=  intval($_POST['id']);
        $constant_id = intval($_POST['constant_id']);
        if(empty($id)){
            $constant_name = D('Constant')->where("id={$constant_id}")->getField('constant_name');
        }else{
            if(empty($constant_id)){
                $constant_name = D('ConstantNode')->where("id={$id}")->getField('constant_name');
            }else{
                $constant_name = D('Constant')->where("id={$constant_id}")->getField('constant_name');
            }
        }
        return $constant_name;
    }
}
?>